//
//  IfengLabel.m
//  IfengNews
//
//  Created by tianhy on 12-12-26.
//
//

#import "IfengLabel.h"
@implementation IfengLabel

@synthesize delegate,dataDic,index;
@synthesize level;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.userInteractionEnabled = YES;
    }
    return self;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
//    if([self.comeFrom isEqualToString:@"comment"])
//        [self setLableBgWithIsAddSelectedColor:@"YES"];
    [self setLabelHightedBgColor];
    UITouch *touch = [touches anyObject];
    touchTimeInterval = [touch timestamp];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
    //do something
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesCancelled:touches withEvent:event];
//    [self setLableBgWithIsAddSelectedColor:@"NO"];
    [self setLabelCommonBgColor];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
//    if([self.comeFrom isEqualToString:@"comment"])
    [self setLabelCommonBgColor];
    
    UITouch *touch = [touches anyObject];
    CGPoint locate = [touch locationInView:self];
    CGPoint locateInWindow = [self.window convertPoint:locate fromView:self];
    touchTimeInterval = [touch timestamp] - touchTimeInterval;
    NSInteger tapCount = touch.tapCount;
    if(tapCount == 1 && touchTimeInterval <= 1.0){
        if(delegate && [delegate respondsToSelector:@selector(ifengLabelDidSingleClickAtIndex:withData:withLevel:withLocateInWindow:withLocateInCell:withSizeOfCell:withView:)]){
            [delegate ifengLabelDidSingleClickAtIndex:[NSNumber numberWithInt:index]
                                             withData:dataDic
                                            withLevel:[NSNumber numberWithInt:level]
                                   withLocateInWindow:locateInWindow withLocateInCell:locate withSizeOfCell:self.frame.size
             withView:self];
        }
    }
}

- (void)setLabelHightedBgColor
{
    UIColor *bgColor = RGB(205, 205, 205);
    self.backgroundColor = bgColor;
}

- (void)setLabelCommonBgColor
{
    UIColor *bgColor = RGB(0xf7, 0xf7, 0xf7);
    self.backgroundColor = bgColor;
}


@end
